tinymce.PluginManager.add('gallery', function(editor, url) {
	// 注册一个工具栏按钮名称
	editor.ui.registry.addButton('gallery', {
		text: '素材库',
		onAction: function (e) {
			$Gallery.GalleryDialogOpen({max:10,size:100,is_new:1,suffix:'bmp,gif,jpg,jpeg,png',type:'1', tabs:true,multiple:true,callback:function (res) {
					console.log(res.length);
					if(res.length > 1){
						$.each(res, function (key, val) {
							if(parseInt(val.type) === 1){
								var html='<p><img src="'+val.url+'" alt="'+val.original+'" width="" height="" /></p>';
								editor.insertContent(html);
							} else {
								tinyMCE.activeEditor.setContent(
									`<p>
               <span class="mce-preview-object mce-object-video" contenteditable="false" data-mce-object="video" data-mce-p-allowfullscreen="allowfullscreen" data-mce-p-frameborder="no" data-mce-p-scrolling="no" data-mce-html="%20">
                 <video src=`+val.url+` width="100%" controls="controls"></video>
               </span>
            </p>`
								);
							}
						})
					} else {
						if(parseInt(res.type) === 1){
							var html='<p><img src="'+res.url+'" alt="'+res.original+'" width="" height="" /></p>';
							editor.insertContent(html);
						} else {
							tinyMCE.activeEditor.setContent(
								`<p>
               <span class="mce-preview-object mce-object-video" contenteditable="false" data-mce-object="video" data-mce-p-allowfullscreen="allowfullscreen" data-mce-p-frameborder="no" data-mce-p-scrolling="no" data-mce-html="%20">
                 <video src=`+res.url+` width="100%" controls="controls"></video>
               </span>
            </p>`
							);
						}
					}

				}});
		}
	});

	return {
		getMetadata: function () {
			return  {
				//插件名和链接会显示在“帮助”→“插件”→“已安装的插件”中
				name: "gallery",//插件名称
				url: "http://exampleplugindocsurl.com", //作者网址
			};
		}
	};
});

